package com.intpro.demo.Utils;

import com.intpro.demo.Utils.MyAnnotations.CurrentUserMethodArgumentResolver;
import java.util.List;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@MapperScan("com.intpro.demo.DAO")
public class WebMvcConfg implements WebMvcConfigurer
{


	@Value("${xcloud.uploadPath}")
	private String uploadPath;

	@Override
	public void addInterceptors(InterceptorRegistry registry)
	{
		//注册拦截器 拦截规则
		//多个拦截器时 以此添加 执行顺序按添加顺序
		registry.addInterceptor(getHandlerInterceptor()).addPathPatterns("/api/**");
	}

	@Override
	public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers)
	{
		resolvers.add(new CurrentUserMethodArgumentResolver());
	}

	@Bean
	public AuthorizedInterceptor getHandlerInterceptor()
	{
		return new AuthorizedInterceptor();
	}

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry)
	{
		registry.addResourceHandler("/api/files/**")
				.addResourceLocations("file:///" + uploadPath);
	}

}